package com.zzz.friend.controller.user;

import com.zzz.common.core.constants.HttpConstants;
import com.zzz.common.core.controller.BaseController;
import com.zzz.common.core.domain.R;
import com.zzz.friend.domain.user.dto.UseEmailLoginDTO;
import com.zzz.friend.domain.user.dto.UsePasswordDTO;
import com.zzz.friend.domain.user.dto.UserUpdateDTO;
import com.zzz.friend.domain.user.vo.UserLoginVO;
import com.zzz.friend.domain.user.vo.UserVO;
import com.zzz.friend.service.user.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @BelongsProject: oj-project
 * @BelongsPackage: com.zzz.friend.controller.user
 * @Author: zhai
 * @CreateTime: 2025-10-25  16:08
 * @Description: TODO 用户控制器
 * @Version: 1.0
 */
@Tag(name = "用户端")
@Slf4j
@RestController
@RequestMapping( "/user")
public class UserController extends BaseController {

    @Autowired
    private UserService userService;

//    @PostMapping("/semiSend/sendPhoneCode")
//    @Operation(summary = "发送手机验证码", description = "发送手机验证码")
//    @ApiResponse(responseCode = "1000", description = "操作成功")
//    @ApiResponse(responseCode = "2000", description = "操作失败")
//    public R<Void> sendPhoneCode(@RequestBody UserDTO userDTO) {
//        return toR(userService.sendPhoneCode(userDTO));
//    }
//
//    @PostMapping("/usePhoneCode/login")
//    @Operation(summary = "使用手机验证码登/注册", description = "使用手机验证码登/注册")
//    @ApiResponse(responseCode = "1000", description = "操作成功")
//    @ApiResponse(responseCode = "2000", description = "操作失败")
//    public R<String> usePhoneCodeLogin(@Validated @RequestBody UserDTO userDTO) {
//        return R.success(userService.usePhoneCodeLogin(userDTO.getPhone(), userDTO.getCode()));
//    }

    @PostMapping("/sendEmailCode")
    @Operation(summary = "发送邮箱验证码", description = "发送邮箱验证码")
    @ApiResponse(responseCode = "1000", description = "操作成功")
    @ApiResponse(responseCode = "2000", description = "操作失败")
    public R<Void> sendEmailCode(@Validated @RequestBody UseEmailLoginDTO useEmailLoginDTO) {
        return toR(userService.sendEmailCode(useEmailLoginDTO));
    }

    @PostMapping("/useEmailCode/login")
    @Operation(summary = "使用邮箱验证码登录", description = "使用邮箱验证码登录")
    @ApiResponse(responseCode = "1000", description = "操作成功")
    @ApiResponse(responseCode = "2000", description = "操作失败")
    public R<String> useEmailCodeLogin(@RequestBody UseEmailLoginDTO emailLoginDTO) {
        return R.success(userService.useEmailCodeLogin(emailLoginDTO));
    }

    @PostMapping("/usePassword/login")
    @Operation(summary = "使用密码登录", description = "使用密码登录")
    @ApiResponse(responseCode = "1000", description = "操作成功")
    @ApiResponse(responseCode = "2000", description = "操作失败")
    @ApiResponse(responseCode = "3102", description = "用户不存在")
    public R<String> usePasswordDTO(@RequestBody UsePasswordDTO passwordDTO) {
        return R.success(userService.usePasswordDTO(passwordDTO));
    }

    @DeleteMapping("/logout")
    @Operation(summary = "登出", description = "登出")
    @ApiResponse(responseCode = "1000", description = "操作成功")
    @ApiResponse(responseCode = "2000", description = "操作失败")
    public R<Void> logout(@RequestHeader(HttpConstants.AUTHENTICATION) String token) {
        return toR(userService.logout(token));
    }

    @GetMapping("/info")
    @Operation(summary = "获取用户信息", description = "获取用户信息")
    @ApiResponse(responseCode = "1000", description = "操作成功")
    @ApiResponse(responseCode = "2000", description = "操作失败")
    public R<UserLoginVO> info(@RequestHeader(HttpConstants.AUTHENTICATION) String token) {
        return R.success(userService.info(token));
    }

    @GetMapping("/detail")
    @Operation(summary = "获取用户详细信息", description = "获取用户详细信息")
    @ApiResponse(responseCode = "1000", description = "操作成功")
    @ApiResponse(responseCode = "2000", description = "操作失败")
    public R<UserVO> detail() {
        return R.success(userService.detail());
    }

    @PutMapping("/edit")
    @Operation(summary = "修改用户信息", description = "修改用户信息")
    @ApiResponse(responseCode = "1000", description = "操作成功")
    @ApiResponse(responseCode = "2000", description = "操作失败")
    public R<Void> editUserInfo(@RequestBody UserUpdateDTO userUpdateDTO) {
        return toR(userService.editUserInfo(userUpdateDTO));
    }

    @PutMapping("head-image/update")
    @Operation(summary = "修改用户头像", description = "修改用户头像")
    @ApiResponse(responseCode = "1000", description = "操作成功")
    @ApiResponse(responseCode = "2000", description = "操作失败")
    public R<Void> updateHeadImage(@RequestBody UserUpdateDTO userUpdateDTO) {
        return toR(userService.updateHeadImage(userUpdateDTO.getHeadImage()));
    }

}
